var KOC = require("koc.common.utils");
var Config = require("../../config");
var StateData = require("../statedata");
var CommonUtils = require("../../lib/common-utils");

module.exports = {
  Ajax: require("./page.ajax"),
  Ajaxs: require("./page.ajaxs"),
  OAuth: require("./page.oauth"),
  Heepay: require("./page.heepay"),
  Main: require("./page.main"),
  Member: require("./page.member"),
  Rank: require("./page.rank"),
  ////////////////////////////////////////////
  //母版页
  ////////////////////////////////////////////
  Master: {
    Modal: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = "";
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/modal", {Content: html});
          });
        });
      };
    },
    Main: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = "";
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/main", {Content: html});
          });
        });
      };
    },
    Room: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = '艺人';
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/room", {Content: html});
          });
        });
      };
    },
    Member: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = "";
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/member", {Content: html});
          });
        });
      };
    },
    User: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = "";
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/user", {Content: html});
          });
        });
      };
    },
    Help: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = "";
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/help", {Content: html});
          });
        });
      };
    },
    Blank: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = "";
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/blank", {Content: html});
          });
        });
      };
    },
    MobileIndex: function (page) {
      return function (req, res) {
        //自动登录
        StateData.Cookie.Remember.Login(req, res, function () {
          //写入渠道ID
          StateData.Cookie.ChannelID.Set(res, req.params["clId"] || req.params["_cid"]);
          //写入邀请ID
          StateData.Cookie.InviterID.Set(res, req.params["Key"] || req.params["_iid"]);
          //输出常量
          res.locals.Virtual_Path = Config.Common.Virtual_Path;
          //输出状态
          CommonUtils.Common.PageScript_StateData(res, StateData.Value(req, res));
          //输出URL
          CommonUtils.Common.PageScript_VirtualPath(res, Config.Common.Virtual_Path);
          //渲染页面
          res.locals.Title = "";
          page(req, res, function (err, html) {
            if (err) {
              //转到错误页面
              res.redirect("");
              return;
            }
            res.render("master/qmxzb", {Content: html});
          });
        });
      };
    }
  }
};